# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# This file is based on the AUR package by fatalis <fatalis@fatalis.pw>
# (https://aur.archlinux.org/packages/ida-free)
pkgname=ida-free
pkgver=8.4.240527
pkgrel=1
pkgdesc="Freeware version of the world's smartest and most feature-full disassembler."
groups=('blackarch' 'blackarch-reversing' 'blackarch-disassembler'
        'blackarch-decompiler' 'blackarch-binary')
arch=('x86_64')
url='https://hex-rays.com/ida-free/'
license=('custom:unknown')
makedepends=('fakechroot')
options=('!strip')
_originalname="idafree84_linux.run"
_installer="$_originalname-$pkgver-$pkgrel"
source=("$_installer::https://web.archive.org/web/20240921184600if_/https://out7.hex-rays.com/files/${_originalname}"
        "$pkgname.desktop")
sha512sums=('afe9ce1f51d44e0781322fdb65a8515a6a3cd09ad0a203e6ba01c131e38b135adf034b612455f0e03ebd315fe818d78d2ea32ae9c4e27bd4f3761db46dee6969'
            '47dcb9f5542a329df7d53cd7889c90f09b2edf6e7729a9566da3710df75c269fbf8e5dd1e95c326104c1faa99380f82df3288e8254cfa3be3955fda1212b2ceb')

package() {
  install -d "$pkgdir/opt/$pkgname"
  install -d "$pkgdir/usr/bin"
  install -d "$pkgdir"/usr/share/{icons,applications,licenses/$pkgname}
  install -d "$pkgdir/tmp"

  # chroot is needed to prevent the installer from creating a single file
  # outside of prefix have to copy the installer due to chroot
  cp $_installer $pkgdir
  chmod +x "$pkgdir"/$_installer
  fakechroot chroot "${pkgdir}" /${_installer} --mode unattended \
  --prefix /opt/${pkgname} --installpassword ""
  rm "$pkgdir"/${_installer}
  rm "$pkgdir"/tmp/installbuilder_installer.log
  rmdir "$pkgdir"/tmp

  # the installer needlessly makes a lot of files executable
  find "$pkgdir/opt/$pkgname" -type f -exec chmod -x {} \;
  # make dir permissions consistent with the 7.0 installer
  find "$pkgdir/opt/$pkgname" -type d -exec chmod g-w {} \;
  chmod +x "$pkgdir/opt/$pkgname/"{ida64,assistant}

  rm "$pkgdir"/opt/$pkgname/{uninstall*,Uninstall*}

  install "$srcdir/$pkgname.desktop" "$pkgdir/usr/share/applications"
  ln -s "/opt/$pkgname/appico64.png" "$pkgdir/usr/share/icons/ida-free.png"
  ln -s "/opt/$pkgname/license.txt" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  ln -s "/opt/$pkgname/ida64" "$pkgdir/usr/bin/ida64"
}

